﻿using System;
using System.ComponentModel;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using YaAppoint.Appointments;

namespace YaAppoint.Common
{
    [RemoteService(isEnabled: false)]
    public class CommonAppService() : ApplicationService, ICommonAppService, ITransientDependency
    {

        /// <summary>
        /// 获取枚举值描述
        /// </summary>
        public string GetEnumValueDescription(object value)
        {
            var field = value.GetType().GetField(value.ToString());
            var attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(field!, typeof(DescriptionAttribute));
            return attribute?.Description ?? value.ToString();
        }

        public DayInWeek ToDayInWeek(DayOfWeek dayOfWeek)
        {
            DayInWeek dayInWeek = new DayInWeek();
            switch (dayOfWeek)
            {
                case DayOfWeek.Monday:
                    dayInWeek = DayInWeek.Mon;
                    break;

                case DayOfWeek.Tuesday:
                    dayInWeek = DayInWeek.Tue;
                    break;

                case DayOfWeek.Wednesday:
                    dayInWeek = DayInWeek.Wed;
                    break;

                case DayOfWeek.Thursday:
                    dayInWeek = DayInWeek.Thu;
                    break;

                case DayOfWeek.Friday:
                    dayInWeek = DayInWeek.Fri;
                    break;

                case DayOfWeek.Saturday:
                    dayInWeek = DayInWeek.Sat;
                    break;

                case DayOfWeek.Sunday:
                    dayInWeek = DayInWeek.Sun;
                    break;
            }
            return dayInWeek;
        } 
    }
}
